<?php

namespace App\Kuafu\Guanyuan\Service;

use App\Kuafu\Config\Model\ConfigModel;
use App\Library\Guanyuan\GuanyuanTool;
use GuzzleHttp\Exception\GuzzleException;

class GuanyuanService
{
    /**
     * 获取观远现在需要推送的门店数据
     */
    public static function getShopList()
    {
        $configType = 'guanyuanPushShop';

        //
        $shopList = ConfigModel::getDataPageByType($configType);

        $return = [];
        foreach ($shopList as $list) {

            $value = json_decode($list['value'], true);

            $startTime = $value['startTime'] ?? '+1';
            if (time() - strtotime($startTime) >= 0) {
                $return[$list['key']] = [
                    'shopId'   => $list['key'],
                    'shopName' => $list['name']
                ];
            }
        }

        return $return;
    }

    /**
     * 获得门店营业数据
     * @param string $date 时间筛选
     * @return array
     * @throws GuzzleException
     */
    public static function getShopBusinessData(string $date): array
    {
        $params = [
            [
                'name' => '日期',
                'filterType' => 'EQ',
                'filterValue' => [
                    $date
                ],
            ]
        ];
        return GuanyuanTool::fetch('h98d449754d534b8b990c4e3', 'r7e03eab637c04bdb838e887', $params);
    }

}
